package org.ocean.general.sample.conditional;


import org.ocean.general.sample.enums.JoinEnum;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class JoinRelations {
    List<Relation> relations;

    public List<Relation> getRelations() {
        return relations;
    }

    public void setRelations(List<Relation> relations) {
        this.relations = relations;
    }

    public JoinRelations(Builder builder){
        this.relations = builder.relations;
    }
    public static Builder builder() {
        return new Builder();
    }
    public static class Builder{
        List<Relation> relations;

        public List<Relation> getRelations() {
            return relations;
        }

        public void setRelations(List<Relation> relations) {
            this.relations = relations;
        }

        public Builder(){
            this.relations = new ArrayList<>();
        }

        public JoinRelations build(){
            return new JoinRelations(this);
        }

        public Builder unionJoin(Class<?> originClass, String originAlias, Class<?> targetClass, String targetAlias, String originField, String targetField,
                                 JoinEnum joinWay, JoinSqls joinSqls){
            if(Objects.nonNull(originAlias) && Objects.nonNull(targetClass)){
                Relation relation = new Relation();
                relation.setOriginClass(originClass);
                relation.setOriginAlias(originAlias);
                relation.setTargetClass(targetClass);
                relation.setTargetAlias(targetAlias);
                relation.setOriginField(originField);
                relation.setTargetField(targetField);
                relation.setJoinWay(joinWay);
                relation.setJoinSqls(joinSqls);
                this.relations.add(relation);
            }
            return this;
        }
    }
    public static class Relation{
        private Class<?> originClass;
        private String originAlias;
        private Class<?> targetClass;
        private String targetAlias;
        private String originField;
        private String targetField;
        private JoinEnum joinWay;
        private JoinSqls joinSqls;
        public Relation(){

        }

        public Class<?> getOriginClass() {
            return originClass;
        }

        public void setOriginClass(Class<?> originClass) {
            this.originClass = originClass;
        }

        public String getOriginAlias() {
            return originAlias;
        }

        public void setOriginAlias(String originAlias) {
            this.originAlias = originAlias;
        }

        public Class<?> getTargetClass() {
            return targetClass;
        }

        public void setTargetClass(Class<?> targetClass) {
            this.targetClass = targetClass;
        }

        public String getTargetAlias() {
            return targetAlias;
        }

        public void setTargetAlias(String targetAlias) {
            this.targetAlias = targetAlias;
        }

        public String getOriginField() {
            return originField;
        }

        public void setOriginField(String originField) {
            this.originField = originField;
        }

        public String getTargetField() {
            return targetField;
        }

        public void setTargetField(String targetField) {
            this.targetField = targetField;
        }

        public JoinEnum getJoinWay() {
            return joinWay;
        }

        public void setJoinWay(JoinEnum joinWay) {
            this.joinWay = joinWay;
        }

        public JoinSqls getJoinSqls() {
            return joinSqls;
        }

        public void setJoinSqls(JoinSqls joinSqls) {
            this.joinSqls = joinSqls;
        }
    }

}
